package com.dd;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.chantel.tool.db.DBUtil;
import com.dd.exception.UserNotFoundException;
import com.dd.exception.XiangMuNotFoundException;

public class BuMenManager {
	
	private static final Logger logger = Logger.getLogger(BuMenManager.class
			.getName());
	
	//
	//通过用户的ID返回审核人员所在的部门
	//一个审核人员属于一个部门
	//
	public static BuMenInfo GetUserBuMenInfoByUserID(int userID)
	{


		String selectCommand = "SELECT BuMenInfoTable.* " +
		"FROM BuMenInfoTable " +
		"where BuMenInfoTable.BuMenId " +
			" in  (select  YuanGongBuMenTable.BuMenId " + 
			     " from YuanGongBuMenTable " +
			     " where YuanGongBuMenTable.YuanGongId = "+ ((Integer)(new Integer(userID))).toString() +")";
		logger.info("sql:"+selectCommand);
		DBUtil2 db2 = DBUtil2.getDefaultDBUtil2();
		Map m = db2.getRow(selectCommand);
		if (m == null || m.size()<=0)
			return null;
		int id = ((Integer) m.get("BuMenId")).intValue();			
		String mingCheng = (String)m.get("BuMenMing");	
		int nQuanXian = ((Integer)m.get("QuanXian")).intValue();	
	
		BuMenInfo bm = new BuMenInfo();
		bm.setBuMenMingCheng(mingCheng);
		bm.setId(id);
		bm.setQuanXian(nQuanXian);
		
			
		System.out.print(id);
		System.out.print(mingCheng);
		System.out.print(nQuanXian);
		System.out.println();	
			
		return bm;
		
	}
	//
	//通过部门的ID返回该用户的等级
	//
	public static int GetDengjiByBuMenID(int iBuMenID)
	{
		int nRetDengji = SysGlobals.C_CaiGouYuan;
		
		DBUtil du = DBUtil.getInstance();
		
		String sql = "select* from BuMenInfoTable where Id = " + ((Integer)(new Integer(iBuMenID))).toString();;
		Map m = du.getRow(sql);
		
		nRetDengji = ((Integer)m.get("QuanXian")).intValue();	
		
		return nRetDengji;
	}

	public static void main(String[] args){
		
		BuMenManager.GetUserBuMenInfoByUserID(7);
		
	}
}